package com.intelligence.device.manager.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.intelligence.device.manager.service.DeviceService;
import com.intelligence.device.manager.service.MonpointsDeviceService;
import com.intelligence.entity.pojo.Device;
import com.intelligence.entity.pojo.MeasurementUnit;
import com.intelligence.entity.pojo.MonpointsDevice;
import com.intelligence.entity.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 通用的增删改页面
 *
 * @Author : RulerWood
 * @Data : 2024/6/3 - 15:56
 */
@RestController
@RequestMapping("/device/monpointsDevice")
public class MonpointsDeviceController {

    @Autowired
    private MonpointsDeviceService monpointsDeviceService;

    /**
     * 获取数据列表
     *
     * @param offset   当前页数
     * @param pageSize 每页条目数
     * @return
     */
    @GetMapping("/pageMonpointsDevice")
    public Result<Page<MonpointsDevice>> pageMonpointsDevice(@RequestParam(value = "offset", defaultValue = "1") Integer offset,
                                                             @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        return Result.build(monpointsDeviceService.page(new Page<>(offset, pageSize)), 200, "获取设备日志列表成功");
    }


    @GetMapping("/listMonpointsDevice")
    public Result<List<MonpointsDevice>> listMonpointsDevice() {
        return Result.build(monpointsDeviceService.list(), 200, "获取设备日志列表成功");
    }
    @GetMapping("/listByMidMonpointsDevice")
    Result<List<MonpointsDevice>> listByMidMonpointsDevice(@RequestParam(value = "mid") Integer mid){
        List<MonpointsDevice> midList = monpointsDeviceService.list(new QueryWrapper<MonpointsDevice>().eq("mid", mid.intValue()));
        return Result.build(midList, 200, "获取设备日志列表成功");
    }
    /**
     * 获取单个对象
     *
     * @param id 对象主键
     * @return
     */
    @GetMapping("/getMonpointsDevice/{id}")
    public Result<MonpointsDevice> getMonpointsDevice(@PathVariable(value = "id") Long id) {
        System.err.println("getMonpointsDevice---------------->id------>"+id);
        return Result.build(monpointsDeviceService.getOne(new QueryWrapper<MonpointsDevice>().eq("deviceid",id)), 200, "获取设备日志成功");
    }


    /**
     * 数据的新增
     *
     * @param monpointsDevice 保存对象
     * @return
     */
    @PostMapping("/saveMonpointsDevice")
    public Result saveMonpointsDevice(@RequestBody MonpointsDevice monpointsDevice) {
        monpointsDeviceService.save(monpointsDevice);
        return Result.build(null, 200, "保存设备日志成功");
    }

    /**
     * 数据的修改
     *
     * @param monpointsDevice 修改对象
     * @return
     */
    @PutMapping("/updateMonpointsDevice")
    public Result updateMonpointsDevice(@RequestBody MonpointsDevice monpointsDevice) {
        monpointsDeviceService.updateById(monpointsDevice);
        return Result.build(null, 200, "更新设备日志成功");
    }

    /**
     * 删除某条数据
     *
     * @param id 数据主键
     * @return
     */
    @DeleteMapping("/deleteMonpointsDevice/{id}")
    public Result deleteMonpointsDevice(@PathVariable(value = "id") Integer id) {
        monpointsDeviceService.removeById(id);
        return Result.build(null, 200, "删除设备日志成功");
    }

}
